package com.sun.lib.net.remote;

import com.lzy.okgo.model.Response;
import com.sun.lib.rx.Disposables;

import java.io.File;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2019/1/15.
 * <p>
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */
public abstract class FileObserver implements Observer<Response<File>> {
    private Disposables disposables;

    public FileObserver(Disposables disposables) {
        this.disposables = disposables;
    }

    public FileObserver(){}

    @Override
    public void onSubscribe(Disposable d) {
        if(disposables!=null)
            disposables.add(d);
    }

    @Override
    public void onNext(Response<File> fileResponse) {
        onSuccess(fileResponse.body());
    }

    protected abstract void onSuccess(File file);

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onComplete() {
        onFinish();
    }

    protected void onFinish(){}


}
